<!DOCTYPE html>
<html lang="ch" xmlns:th="http://wwww.thymeleaf.org">
<body>
    <div>
         <input type="file" id="ossInput">
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.16.2/axios.min.js"></script>
<script src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.13.2.min.js"></script>
<script>
    document.getElementById("ossInput")
        //选择文件的事件
        .addEventListener("input", (e) => {
        //请求后端拿到token
            axios.get('/oss/getToken ')
                .then((response) => {
                    let ossConfig = response.data;
                    console.log(ossConfig)
                    //根都token构透上传工具
                        let client = new OSS({
                        region: ossConfig.region,
                        secure:true,
                        accessKeyId: ossConfig.accesskeyId,
                        accessKeySecret: ossConfig.accesskeySecret,
                        stsToken: ossConfig.stsToken,
                        bucket: ossConfig.bucket
                    });
                        console.log(client)
                        debugger
                    //上传文件
                    client.put(e.target.files[0].name, e.target.files[0])
                })
        })
</script>
</html>
